<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'reg.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		#info{
			border:1px solid #000;
			background-color: #ccc;
			font-size: 12px;
		}
	</style>
	<script type="text/javascript">
	    var xhr;
		function checkName(val){
			//1.创建核心对象
			xhr = new XMLHttpRequest();
			//2.打开连接
			xhr.open("GET", "userServlet?uname="+val);
			//3.发送请求
			xhr.send(null);
			//4.处理响应
			xhr.onreadystatechange=mycallback;
		}
		function mycallback(){
			if(xhr.readyState==4 && xhr.status==200){				
				if("true"==xhr.responseText){
					document.getElementById("info").innerHTML="用户名已存在";
					document.getElementById("info").style.className="errorStyle";
				}else{
					document.getElementById("info").innerHTML="可以注册";
				}
			}
		}
	
	
	</script>


  </head>
  
  <body>
    <form action="" name="form1">
    用户账号：<input type="text" name="uname" id="uname" onblur="checkName(this.value)">
    <span id="info"></span><br/>
  用户密码:  <input type="password" name="upwd" id="upwd"><br/>
  <input type="submit" value="注册" id="btn1"> 
    </form>
    
    
    
  </body>
</html>
